package javagprssrv.Task;

import javagprssrv.Common.DateTime;
import javagprssrv.StructClass.structCOMMTerm;
import javagprssrv.StructClass.structTask;
import javagprssrv.JGS_Param;

public class TaskExecutor extends java.lang.Thread
{
    int idxTask;
    java.lang.String Task_ID;
    java.lang.String TelNO;
    int TermType;
    int TaskState;
    
    public TaskExecutor() {
        super("TaskExecutor");
        this.idxTask = -1;
    }
    
    @java.lang.Override
    public void run() {
        javagprssrv.JGS_Param.myLog.ShowLog("线程TaskExecutor正在运行。", true, true);
        JGS_Param.myLog.ShowLog("线程TaskExecutor正在运行。", Boolean.valueOf(true), Boolean.valueOf(true));
        try
        {
          while (true)
          {
            Thread.sleep(100L);
            if (this.idxTask == -1)
            {
              boolean isFindTask = false;
              synchronized (JGS_Param.Tasks)
              {
                for (int i = 0; i < JGS_Param.Tasks.size(); i++) {
                  if (((structTask)JGS_Param.Tasks.elementAt(i)).Task_State == 0)
                  {
                    this.idxTask = i;
                    this.Task_ID = ((structTask)JGS_Param.Tasks.elementAt(i))._TaskID;
                    this.TelNO = ((structTask)JGS_Param.Tasks.elementAt(i)).Task_TelNo;
                    isFindTask = true;
                    
                    break;
                  }
                }
              }
              this.TermType = ((structTask)JGS_Param.Tasks.elementAt(this.idxTask)).TermType;
              if (this.TermType == 0) {
                do_UDP_Dial();
              }
              if ((this.TermType == 1) && (
              

                (this.TermType == 2) && 
                

                (this.TermType != 6))) {}
            }
            else
            {
              boolean isTaskFinished = false;
              if (((structTask)JGS_Param.Tasks.elementAt(this.idxTask))._TaskID != this.Task_ID) {
                isTaskFinished = true;
              }
              if (((structTask)JGS_Param.Tasks.elementAt(this.idxTask)).Task_TelNo != this.TelNO) {
                isTaskFinished = true;
              }
              if (((structTask)JGS_Param.Tasks.elementAt(this.idxTask)).Task_State == 9) {
                isTaskFinished = true;
              }
              if (isTaskFinished) {
                this.idxTask = -1;
              }
            }
          }
        }
        catch (Exception e) {}
    }
    
    private void do_UDP_Dial() {
        int idx = -1;
        synchronized (javagprssrv.JGS_Param.COMMTerms) {
            for (int idxCommTerm = 0; idxCommTerm < javagprssrv.JGS_Param.COMMTerms.size(); ++idxCommTerm) {
                if (javagprssrv.JGS_Param.COMMTerms.elementAt(idxCommTerm).isFree) {
                    idx = idxCommTerm;
                    javagprssrv.JGS_Param.COMMTerms.elementAt(idx).isFree = false;
                    break;
                }
            }
        }
        if (idx > -1) {
            javagprssrv.JGS_Param.Tasks.elementAt(this.idxTask).Task_State = 1;
            javagprssrv.JGS_Param.Tasks.elementAt(this.idxTask).Task_StartDateTime = new javagprssrv.Common.DateTime().getDateTime("YYYY-MM-DD HH:NN:SS");
            javagprssrv.JGS_Param.COMMTerms.elementAt(idx).SB.COMM_Dial(this.TelNO, javagprssrv.JGS_Param._DialSeconds);
            javagprssrv.JGS_Param.COMMTerms.elementAt(idx).isFree = true;
        }
    }
}
